/*
 * Copyright 2011 CraneLeeon authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.crane.webtemplate.dao;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 *
 * @author CraneLeeon
 */
public class Filter {
// <editor-fold defaultstate="collapsed" desc="constant">

    public static final class InOrNotIn<T> {
        private String field;
        private boolean in;
        private Object[] objs;

        public InOrNotIn(String field, boolean in, Object[] objs) {
            this.field = field;
            this.in = in;
            this.objs = objs;
        }

        public String getField() {
            return field;
        }

        public void setField(String field) {
            this.field = field;
        }

        public boolean isIn() {
            return in;
        }

        public void setIn(boolean in) {
            this.in = in;
        }

        public Object[] getObjs() {
            return objs;
        }

        public void setObjs(Object[] objs) {
            this.objs = objs;
        }
    }

//    public static final class EVAL {
//
//        public final static int NO = -1;
//        public final static int EQUAL = 0;
//        public final static int GE = 1;
//        public final static int GT = 2;
//        public final static int LE = 3;
//        public final static int LT = 4;
//    }
//
//    public static final class BLUR {
//
//        public final static int NO = 0;
//        public final static int ANY_WHERE = 1;
//        public final static int START = 2;
//        public final static int END = 3;
//    }
//
//    public static final class DECIDE {
//
//        public final static int DECIDE_IS = 1;
//        public final static int DECIDE_NOT = -1;
//        public final static int DECIDE_CARELESS = 0;
//    }

// </editor-fold>
    protected String whereStr; //NOTICE: $. must be prifix for every search field, they will be replace at query stage
    protected Object[] whereParams;
    protected Map<String, Object> whereParams_Named;
    protected Integer limit;
    protected Integer offset;
    protected List<Map.Entry<String, String>> sorters;
    protected List<InOrNotIn> inOrNotIns;

    public Map<String, Object> getWhereParams_Named() {
        return whereParams_Named;
    }

    public void setWhereParams_Named(Map<String, Object> whereParams_Named) {
        this.whereParams_Named = whereParams_Named;
    }

    public List<Map.Entry<String, String>> getSorters() {
        return sorters;
    }

    public void setSorters(List<Map.Entry<String, String>> sorters) {
        this.sorters = sorters;
    }

    public Filter() {
    }

    public Filter(String whereStr, Object[] whereParams) {
        this.whereStr = whereStr;
        this.whereParams = whereParams;
    }

    public Filter(String whereStr, Object[] whereParams, Integer limit, Integer offset) {
        this.whereStr = whereStr;
        this.whereParams = whereParams;
        this.limit = limit;
        this.offset = offset;
    }

    public Filter(String whereStr, Object[] whereParams, Integer limit, Integer offset, List<Map.Entry<String, String>> sorters) {
        this.whereStr = whereStr;
        this.whereParams = whereParams;
        this.limit = limit;
        this.offset = offset;
        this.sorters = sorters;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public String getWhereStr() {
        return whereStr;
    }

    /***
     * NOTICE: using the class name as prefix and replace all '.' with '_',
     * (e.g) PLU.class.getName().replaceAll("\\.", "_")+".code".
     * $. represent current working DAO referd BO.
     * (e.g) $.code = '100001' and $.name like :name
     * @param whereStr
     */
    public void setWhereStr(String whereStr) {
        this.whereStr = whereStr;
    }

    public Object[] getWhereParams() {
        return whereParams;
    }

    public void setWhereParams(Object[] whereParams) {
        this.whereParams = whereParams;
    }

    public List<InOrNotIn> getInOrNotIns() {
        return inOrNotIns;
    }

    public void setInOrNotIns(List<InOrNotIn> inOrNotIns) {
        this.inOrNotIns = inOrNotIns;
    }


}
